COLOR Statement ---------------------------------------------------------------------------- Action Sets the foreground and background colors for the display. Syntax 1 COLOR -foreground&--, -background&--, border&-- Screen mode 0 (text only) Syntax 2 COLOR -background&--, palette%- Screen mode 1 Syntax 3 COLOR -foreground&- Screen mode 4 Syntax 4 COLOR -foreground&--, background&- Screen modes 7-10 Syntax 5 COLOR -foreground&- Screen modes 12,13 Remarks With the COLOR statement, you can set the foreground or background colors for the display. In screen mode 0, a border color also can be selected. In screen mode 1, no foreground color can be selected, but one of two three-color palettes can be selected for use with graphic statements. In screen modes 4, 12, and 13, only the foreground color can be set. The COLOR statement does not determine the range of available colors. The combination of adapter, display, and screen mode determines the color range. If you use COLOR statement arguments outside these valid ranges, BASIC generates the error message Illegal function call. For more information, see the entry for the SCREEN statement. The COLOR statement uses the following arguments. ----------------------------------------------------------------------------- Argument Description ---------------------------------------------------------------------------- foreground& Text color attribute in screen mode 0; text or line-drawing display color in screen mode 4; text and line-drawing color attribute in screen modes 7-10, 12, and 13. background& Color code or color attribute for screen background. Argument Description ---------------------------------------------------------------------------- screen background. border& Color code for the area surrounding the screen. palette% In screen mode 1, one of two three-color palettes. is green, red, and brown; 1 is cyan, magenta, and bright white. The different versions of syntax and their effects in different screen modes are described in the following table. ----------------------------------------------------------------------------- Screen mode Syntax and description Screen mode Syntax and description ---------------------------------------------------------------------------- 0 COLOR -foreground&--, - background&--, border&-- Modifies the current default text foreground and background colors and the screen border. The foreground& color value must be an integer expression between 0 and 31, inclusive. It determines the foreground color in text mode -- the default color of text. Sixteen colors can be selected with the integers 0-15. A blinking version of a color is specified by adding 16 to the color number. For example, a blinking color 7 is equal to 7 + 16, or 23. The background& color value is an Screen mode Syntax and description ---------------------------------------------------------------------------- The background& color value is an integer expression between 0 and 7, inclusive, and is the color of the background for each text character. Blinking background colors are not supported. The border& color, which fills the screen area outside the text area, is an integer expression between 0 and 15, inclusive. Note that the border& argument has no effect with the following adapters. the IBM Enhanced Graphics Adapter (EGA), the IBM Video Graphics Array adapter (VGA), and the IBM Multicolor Graphics Array adapter (MCGA). Screen mode Syntax and description ---------------------------------------------------------------------------- 1 COLOR -background&--, palette%- The background& color value must be an integer expression between 0 and 3, inclusive. The argument palette% is an integer expression with an odd or even value between 0 and 255, inclusive. An even value makes available one set of three default foreground colors, and an odd value makes available a different default set. The default colors for palette% are equivalent to the following PALETTE statements on a system Screen mode Syntax and description ---------------------------------------------------------------------------- PALETTE statements on a system equipped with an EGA. ' Definition of the even palette-number set. COLOR ,0' In screen mode 1, an even palette ' number is equivalent to. PALETTE 1,2 ' EGA Attribute 1 = color 2 (green) PALETTE 2,4 ' EGA Attribute 2 = color 4 (red) PALETTE 3,6 ' EGA Attribute 3 = color 6 (yellow) ' Definition of the odd palette-number set. COLOR ,1' In screen mode 1, an odd palette ' number is equivalent to. PALETTE 1,3 ' EGA Attribute 1 = color 3 (cyan) PALETTE 2,5 ' EGA Attribute 2 = color 5 (magenta) PALETTE 3,7 ' EGA Attribute 3 = color 7 (white) ----------------------------------------------------------------------------- Screen mode Syntax and description ---------------------------------------------------------------------------- Note that in screen mode 1, a COLOR statement overrides PALETTE statements that were executed previously. 4 COLOR -foreground&- The screen foreground& color value must be an integer expression between 0 and 15, inclusive. This expression sets the display color associated with color attribute 1 only. The screen background color is fixed as black. 7-10 COLOR -foreground&--, background&- The argument foreground&, the Screen mode Syntax and description ---------------------------------------------------------------------------- The argument foreground&, the line-drawing color, is a color attribute. The argument background&, the screen color, is a display color. 12, 13 COLOR -foreground&- The argument foreground&, the line drawing color, is a color attribute. BASIC generates the error message Illegal function call if the COLOR statement is used in screen modes 2, 3, or 11. Use the PALETTE statements to set the color in screen mode 11. The foreground can be the same color as the background, making characters and graphics invisible. The default background color is black for all display hardware configurations and all screen modes. This background is produced by the default display color of 0 associated with the background color attribute of 0. In screen modes 12 and 13 you can set the background color by assigning a color to attribute 0 with a PALETTE statement. For example, to make the background color 8224 (an olive drab), you would use the following PALETTE statement. PALETTE 0,8224 To make the background color bright red-violet, use the following PALETTE statement. PALETTE 0, 4128831 In screen mode 11 you can set both the foreground and background color by assigning a color to attribute 0 with a PALETTE statement. With an EGA, VGA, or MCGA installed, the PALETTE statement gives you flexibility in assigning different display colors to the color-attribute ranges for the foreground&, background&, and border& colors. For more information, see the PALETTE statement. See Also PAINT, PALETTE, SCREEN Statement Example The following series of examples show COLOR statements and their effects in the various screen modes. SCREEN 0 ' Text mode only. ' Foreground& = 1 (blue), background& = 2 (green), border& = 3 (cyan). ' EGA and VGA boards do not support the border& argument. COLOR 1, 2, 3 CLS LOCATE 12, 25. PRINT "Press any key to continue..." DO . LOOP WHILE INKEY$ = "" SCREEN 1 ' Set screen to 320 x 200 graphics. ' Background& = 1 (blue). ' Foreground& = even palette number (red, green, yellow). COLOR 1, 0 LINE (20, 20)-(300, 180), 3, B ' Draw a brown box. LOCATE 12, 7. PRINT "Press any key to continue..." DO . LOOP WHILE INKEY$ = "" ' Background& = 2 (green). ' Foreground& = odd palette number (white, magenta, cyan). COLOR 2, 1 LINE (20, 20)-(300, 180), 3, B ' Draw a bright white box. LOCATE 12, 7. PRINT "Press any key to continue..." DO . LOOP WHILE INKEY$ = "" SCREEN 0 ' Set screen to text mode. ' Foreground& = 7 (white), background& = 0 (black), border& = 0 ' (black). COLOR 7, 0, 0 CLS END ----------------------------------------------------------------------------